package cn.tedu.bece.admin.system.controller;

import cn.tedu.bece.admin.common.service.CaptchaService;
import cn.tedu.bece.admin.common.response.JsonResult;
import cn.tedu.bece.admin.system.service.IFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Api(tags = "00.公用模块")
@RestController
public class CommonController {

    @Autowired
    private IFileService fileService;

    @Autowired
    private CaptchaService captchaService;

    @ApiOperation(value = "上传图片")
    @PostMapping("/api/uploadImage")
    public JsonResult uploadImage(@RequestPart("file") MultipartFile multipartFile) {
        String url = fileService.uploadImage("images", multipartFile);
        return JsonResult.success(url);
    }

    @ApiOperation(value = "图形验证码")
    @GetMapping("/api/captcha")
    public JsonResult captcha() {
        Map<String, Object> result = captchaService.generateCaptcha();
        return JsonResult.success(result);
    }

}
